from django.db import models
from django.conf import settings

from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractUser
# Create your models here.


class Students(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,null=True, blank=True)
    username = models.CharField(verbose_name="学号", max_length=15, unique=True,null=True, blank=True)
    student_name = models.CharField(verbose_name="姓名", max_length=50,null=True, blank=True)
    classname = models.CharField(verbose_name="所属班级", max_length=50,null=True, blank=True)
    reserveField = models.CharField(verbose_name="预留字段", max_length=20, null=True, blank=True)
    def __str__(self):
        return str(self.student_name)

class Courses(models.Model):
    # student = models.ManyToManyField(to="Students",related_name="Course_Stu")#与学生表是多对多的关系
    courseid = models.CharField(verbose_name="课程id", max_length=20, null=True, blank=True) #必填
    coursename = models.CharField(verbose_name="课程名", max_length=40, null=True, blank=True) #必填
    teacher = models.CharField(verbose_name="任课教师", max_length=20, null=True, blank=True) #必填
    schooltime = models.CharField(verbose_name="上课时间",  max_length=100, null=True, blank=True) #必填
    place = models.CharField(verbose_name="上课地点", max_length=100, null=True, blank=True) #非必填

    grades = models.FloatField(verbose_name="课程评分", default=0)
    reserveField = models.CharField(verbose_name="预留字段", max_length=20, null=True, blank=True)
    def __str__(self):
        return str(self.coursename)

#对应于数据库中的选课表
class SelectClass(models.Model):
    studentid = models.ForeignKey(Students, models.CASCADE)
    courseid = models.ForeignKey(Courses, models.CASCADE)
    coursename = models.CharField(verbose_name="课程名", max_length=40, null=True, blank=True) #必填
    comment = models.TextField(verbose_name="评论", null=True, blank=True)

#对应于数据库中的评论表
class Comments(models.Model):
    studentid = models.ForeignKey(Students, models.CASCADE)
    coursename = models.CharField(verbose_name="课程名", max_length=40, null=True, blank=True) #必填
    comment = models.TextField(verbose_name="评论", null=True, blank=True)